package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyGetcashVo;
import com.ruoyi.system.bo.ZsyyGetcashQueryBo;
import com.ruoyi.system.bo.ZsyyGetcashAddBo;
import com.ruoyi.system.bo.ZsyyGetcashEditBo;
import com.ruoyi.system.service.IZsyyGetcashService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 提现记录Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "提现记录控制器", tags = {"提现记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/getcash")
public class ZsyyGetcashController extends BaseController {

    private final IZsyyGetcashService iZsyyGetcashService;

    /**
     * 查询提现记录列表
     */
    @ApiOperation("查询提现记录列表")
    @PreAuthorize("@ss.hasPermi('system:getcash:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyGetcashVo> list(@Validated ZsyyGetcashQueryBo bo) {
        return iZsyyGetcashService.queryPageList(bo);
    }

    /**
     * 导出提现记录列表
     */
    @ApiOperation("导出提现记录列表")
    @PreAuthorize("@ss.hasPermi('system:getcash:export')")
    @Log(title = "提现记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyGetcashVo> export(@Validated ZsyyGetcashQueryBo bo) {
        List<ZsyyGetcashVo> list = iZsyyGetcashService.queryList(bo);
        ExcelUtil<ZsyyGetcashVo> util = new ExcelUtil<ZsyyGetcashVo>(ZsyyGetcashVo.class);
        return util.exportExcel(list, "提现记录");
    }

    /**
     * 获取提现记录详细信息
     */
    @ApiOperation("获取提现记录详细信息")
    @PreAuthorize("@ss.hasPermi('system:getcash:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyGetcashVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyGetcashService.queryById(id));
    }

    /**
     * 新增提现记录
     */
    @ApiOperation("新增提现记录")
    @PreAuthorize("@ss.hasPermi('system:getcash:add')")
    @Log(title = "提现记录", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyGetcashAddBo bo) {
        return toAjax(iZsyyGetcashService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改提现记录
     */
    @ApiOperation("修改提现记录")
    @PreAuthorize("@ss.hasPermi('system:getcash:edit')")
    @Log(title = "提现记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult edit(@Validated @RequestBody ZsyyGetcashEditBo bo) {
        return iZsyyGetcashService.updateByEditBo(bo);
    }

    /**
     * 删除提现记录
     */
    @ApiOperation("删除提现记录")
    @PreAuthorize("@ss.hasPermi('system:getcash:remove')")
    @Log(title = "提现记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyGetcashService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
